import os
import configparser
import requests

config = configparser.ConfigParser()
config.read('../Config/config.ini')


project_path = config.get('ProjectInfo', 'project_path')
project_name = config.get('ProjectInfo', 'project_name')
git_Username = config.get('UserInfo', 'git_Username')
git_version = requests.get(f"https://api.github.com/repos/{git_Username}/{project_name}/releases/latest")


def get_version():
    with open(project_path + "/" + project_name + '/Config/Version.ini', 'r') as f:
        return f.read().strip()


USERNAME = git_Username
REPO_NAME = project_name
RELEASE_VERSION = get_version()


def PublishRelease():
    os.system(f'git tag {RELEASE_VERSION}')
    print(f'Created Git tag({RELEASE_VERSION})')
    os.system(f'git push origin {RELEASE_VERSION}')
    print(f'Pushed origin')
    os.system(f'gh release create {RELEASE_VERSION} --title "{RELEASE_VERSION}" --generate-notes --latest')
    print('Release created')

